package com.tedu.jsd2407_ivos_fzj.vehicle.controller;

import com.tedu.jsd2407_ivos_fzj.base.response.JsonResult;
import com.tedu.jsd2407_ivos_fzj.vehicle.pojo.dto.VehicleQuery;
import com.tedu.jsd2407_ivos_fzj.vehicle.pojo.dto.VehicleSaveParam;
import com.tedu.jsd2407_ivos_fzj.vehicle.pojo.vo.VehicleVO;
import com.tedu.jsd2407_ivos_fzj.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/vehicle")
@Slf4j
public class VehicleController {
    @Autowired//按类型匹配,当容器中有多个相同类型的 Bean 时，可以使用 @Qualifier 注解来显式指定注入哪一个 Bean
    private VehicleService vehicleService;

    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("车辆查询，参数：{}",vehicleQuery);
        List<VehicleVO> vehicleVOList = vehicleService.select(vehicleQuery);
        log.debug("车辆查询，结果：{}",vehicleVOList);
        return JsonResult.ok(vehicleVOList);
    }
    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        vehicleService.save(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除车辆，参数：{}",id);
        vehicleService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/unbind/{id}")
    public JsonResult unbind(@PathVariable Long id){
        log.debug("解绑车辆，参数：{}",id);
        vehicleService.removeGeofenceBindStatus(id);
        return JsonResult.ok();
    }
    @PostMapping("/bind/{id}/{geofenceId}")
    public JsonResult bind(@PathVariable Long id,@PathVariable Long geofenceId){
        log.debug("绑定围栏，参数：{},{}",id,geofenceId);
        vehicleService.bindGeofence(id, geofenceId);
        return JsonResult.ok();
    }


}
